This notebook simulates the Minimum Leakage Interference Alignment algorithm.
In [1]:
# xxxxxxxxxx Add the parent folder to the python path. xxxxxxxxxxxxxxxxxxxx
import sys
import os
pyphysim_folder = "~/cvs_files/pyphysim/"
pyphysim_folder = os.path.expanduser(pyphysim_folder)
sys.path.append(pyphysim_folder)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Import the simulation runner
from apps.simulate_ia_minleakage import MinLeakageSimulationRunner
from util import simulations
# We will use clear_output to erase the progressbar after the simulation has finished.
from IPython.display import clear_output
# We will use pprint to print the simulation parameters
from pprint import pprint
The configuration of the simulation is in the 'ia_config_file_120.txt' file. You can edit and run the cell below to update the configuration file.
In [2]:
%%file ia_config_file_120.txt
[Scenario]
SNR = [ 0. 5. 10. 15. 20. 25. 30.]
M = 4
modulator = PSK
NSymbs = 100
K = 3
Nr = 2
Nt = 2
Ns = 1
[IA Algorithm]
max_iterations = 120
[General]
rep_max = 5000
max_bit_errors = 10000
unpacked_parameters = SNR,
All we need to do now is creating the runner object, call its "simulate" method and save the results to a file.
In [3]:
runner_120 = MinLeakageSimulationRunner('ia_config_file_120.txt')
pprint(runner_120.params.parameters)
runner_120.simulate()
# Clear the progressbar output after the simulation ends.
clear_output()
# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = runner_120.params["K"]
Nr = runner_120.params["Nr"]
Nt = runner_120.params["Nt"]
Ns = runner_120.params["Ns"]
modulator_name = runner_120.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_120 = 'ia_min_leakage_results_{0}_{1}x{2}({3})_120'.format(modulator_name,
Nr,
Nt,
Ns)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxx Save the simulation results to a file xxxxxxxxxxxxxxxxxxxx
runner_120.results.save_to_file('{0}.pickle'.format(results_filename_120))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print "Runned iterations: {0}".format(runner_120.runned_reps)
print "Elapsed Time: {0}".format(runner_120.elapsed_time)
Just to be sure, lets create another runner object and repeat the simulation.
In [4]:
runner_120_another = MinLeakageSimulationRunner('ia_config_file_120.txt')
pprint(runner_120_another.params.parameters)
runner_120_another.simulate()
# Clear the progressbar output after the simulation ends.
clear_output()
# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = runner_120_another.params["K"]
Nr = runner_120_another.params["Nr"]
Nt = runner_120_another.params["Nt"]
Ns = runner_120_another.params["Ns"]
modulator_name = runner_120_another.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_120_another = 'ia_min_leakage_results_{0}_{1}x{2}({3})_120_another'.format(modulator_name,
Nr,
Nt,
Ns)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxx Save the simulation results to a file xxxxxxxxxxxxxxxxxxxx
runner_120_another.results.save_to_file('{0}.pickle'.format(results_filename_120_another))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print "Runned iterations: {0}".format(runner_120_another.runned_reps)
print "Elapsed Time: {0}".format(runner_120_another.elapsed_time)
Plot the results for the first simulation
In [5]:
results_120 = simulations.SimulationResults.load_from_file('{0}.pickle'.format(
results_filename_120))
# Get the BER and SER from the results object
ber = results_120.get_result_values_list('ber')
ser = results_120.get_result_values_list('ser')
ia_iterations = results_120.params['max_iterations']
# Get the SNR from the simulation parameters
SNR = np.array(results_120.params['SNR'])
# Can only plot if we simulated for more then one value of SNR
if SNR.size > 1:
fig = figure(figsize=(12,9))
semilogy(SNR, ber, '--g*', label='BER')
semilogy(SNR, ser, '--b*', label='SER')
xlabel('SNR')
ylabel('Error')
title('Min Leakage IA Algorithm ({5} Iterations)\nK={0}, Nr={1}, Nt={2}, Ns={3}, {4}'.format(K, Nr, Nt, Ns, modulator_name, ia_iterations))
legend()
grid(True, which='both', axis='both')
show()
Plot the results from the second simulation
In [6]:
results_120_another = simulations.SimulationResults.load_from_file('{0}.pickle'.format(
results_filename_120_another))
# Get the BER and SER from the results object
ber_another = results_120_another.get_result_values_list('ber')
ser_another = results_120_another.get_result_values_list('ser')
ia_iterations_another = results_120_another.params['max_iterations']
# Get the SNR from the simulation parameters
SNR_another = np.array(results_120_another.params['SNR'])
# Can only plot if we simulated for more then one value of SNR
if SNR_another.size > 1:
fig = figure(figsize=(12,9))
semilogy(SNR_another, ber_another, '--g*', label='BER')
semilogy(SNR_another, ser_another, '--b*', label='SER')
xlabel('SNR')
ylabel('Error')
title('Min Leakage IA Algorithm ({5} Iterations)\nK={0}, Nr={1}, Nt={2}, Ns={3}, {4}'.format(K, Nr, Nt, Ns, modulator_name, ia_iterations_another))
legend()
grid(True, which='both', axis='both')
show()
First we need to create a "view" of the engines. Note that you need to start the engines before calling the code below.
In [7]:
from IPython.parallel import Client
cl = Client()
dview = cl.direct_view()
# Add the folder containing PyPhysim to the python path in all the
# engines
dview.execute('import sys')
dview.execute('sys.path.append("{0}")'.format(pyphysim_folder))
Out[7]:
In [8]:
runner_120_parallel = MinLeakageSimulationRunner('ia_config_file_120.txt')
pprint(runner_120_parallel.params.parameters)
runner_120_parallel.simulate_in_parallel(dview)
# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = runner_120_parallel.params["K"]
Nr = runner_120_parallel.params["Nr"]
Nt = runner_120_parallel.params["Nt"]
Ns = runner_120_parallel.params["Ns"]
modulator_name = runner_120_parallel.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_120_parallel = 'ia_min_leakage_results_{0}_{1}x{2}({3})_120_parallel'.format(modulator_name,
Nr,
Nt,
Ns)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxx Save the simulation results to a file xxxxxxxxxxxxxxxxxxxx
runner_120_parallel.results.save_to_file('{0}.pickle'.format(results_filename_120_parallel))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print "Runned iterations: {0}".format(runner_120_parallel.runned_reps)
print "Elapsed Time: {0}".format(runner_120_parallel.elapsed_time)
In [9]:
results_120_parallel = simulations.SimulationResults.load_from_file('{0}.pickle'.format(
results_filename_120_parallel))
# Get the BER and SER from the results object
ber_parallel = results_120_parallel.get_result_values_list('ber')
ser_parallel = results_120_parallel.get_result_values_list('ser')
ia_iterations_parallel = results_120_parallel.params['max_iterations']
# Get the SNR from the simulation parameters
SNR_parallel = np.array(results_120_parallel.params['SNR'])
# Can only plot if we simulated for more then one value of SNR
if SNR_parallel.size > 1:
fig = figure(figsize=(12,9))
semilogy(SNR_parallel, ber_parallel, '--g*', label='BER')
semilogy(SNR_parallel, ser_parallel, '--b*', label='SER')
xlabel('SNR')
ylabel('Error')
title('Min Leakage IA Algorithm ({5} Iterations)\nK={0}, Nr={1}, Nt={2}, Ns={3}, {4}'.format(K, Nr, Nt, Ns, modulator_name, ia_iterations_parallel))
legend()
grid(True, which='both', axis='both')
show()
In [10]:
%%file ia_config_file_60.txt
[Scenario]
SNR = [ 0. 5. 10. 15. 20. 25. 30.]
M = 4
modulator = PSK
NSymbs = 100
K = 3
Nr = 2
Nt = 2
Ns = 1
[IA Algorithm]
max_iterations = 60
[General]
rep_max = 5000
max_bit_errors = 10000
unpacked_parameters = SNR,
In [11]:
runner_60_parallel = MinLeakageSimulationRunner('ia_config_file_60.txt')
pprint(runner_60_parallel.params.parameters)
runner_60_parallel.simulate_in_parallel(dview)
# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = runner_60_parallel.params["K"]
Nr = runner_60_parallel.params["Nr"]
Nt = runner_60_parallel.params["Nt"]
Ns = runner_60_parallel.params["Ns"]
modulator_name = runner_60_parallel.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_60_parallel = 'ia_min_leakage_results_{0}_{1}x{2}({3})_60_parallel'.format(modulator_name,
Nr,
Nt,
Ns)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxx Save the simulation results to a file xxxxxxxxxxxxxxxxxxxx
runner_60_parallel.results.save_to_file('{0}.pickle'.format(results_filename_60_parallel))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print "Runned iterations: {0}".format(runner_60_parallel.runned_reps)
print "Elapsed Time: {0}".format(runner_60_parallel.elapsed_time)
In [12]:
results_60_parallel = simulations.SimulationResults.load_from_file('{0}.pickle'.format(
results_filename_60_parallel))
# Get the BER and SER from the results object
ber_parallel = results_60_parallel.get_result_values_list('ber')
ser_parallel = results_60_parallel.get_result_values_list('ser')
ia_iterations_parallel = results_60_parallel.params['max_iterations']
# Get the SNR from the simulation parameters
SNR_parallel = np.array(results_60_parallel.params['SNR'])
# Can only plot if we simulated for more then one value of SNR
if SNR_parallel.size > 1:
fig = figure(figsize=(12,9))
semilogy(SNR_parallel, ber_parallel, '--g*', label='BER')
semilogy(SNR_parallel, ser_parallel, '--b*', label='SER')
xlabel('SNR')
ylabel('Error')
title('Min Leakage IA Algorithm ({5} Iterations)\nK={0}, Nr={1}, Nt={2}, Ns={3}, {4}'.format(K, Nr, Nt, Ns, modulator_name, ia_iterations_parallel))
legend()
grid(True, which='both', axis='both')
show()
In [13]:
%%file ia_config_file_5.txt
[Scenario]
SNR = [ 0. 5. 10. 15. 20. 25. 30.]
M = 4
modulator = PSK
NSymbs = 100
K = 3
Nr = 2
Nt = 2
Ns = 1
[IA Algorithm]
max_iterations = 5
[General]
rep_max = 5000
max_bit_errors = 10000
unpacked_parameters = SNR,
In [14]:
runner_5_parallel = MinLeakageSimulationRunner('ia_config_file_5.txt')
pprint(runner_5_parallel.params.parameters)
runner_5_parallel.simulate_in_parallel(dview)
# xxxxxxxxxx Get the parameters xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
K = runner_5_parallel.params["K"]
Nr = runner_5_parallel.params["Nr"]
Nt = runner_5_parallel.params["Nt"]
Ns = runner_5_parallel.params["Ns"]
modulator_name = runner_5_parallel.modulator.name
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# File name (without extension) for the figure and result files.
results_filename_5_parallel = 'ia_min_leakage_results_{0}_{1}x{2}({3})_5_parallel'.format(modulator_name,
Nr,
Nt,
Ns)
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# xxxxxxxxxx Save the simulation results to a file xxxxxxxxxxxxxxxxxxxx
runner_5_parallel.results.save_to_file('{0}.pickle'.format(results_filename_5_parallel))
# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
print "Runned iterations: {0}".format(runner_5_parallel.runned_reps)
print "Elapsed Time: {0}".format(runner_5_parallel.elapsed_time)
In [15]:
results_5_parallel = simulations.SimulationResults.load_from_file('{0}.pickle'.format(
results_filename_5_parallel))
# Get the BER and SER from the results object
ber_parallel = results_5_parallel.get_result_values_list('ber')
ser_parallel = results_5_parallel.get_result_values_list('ser')
ia_iterations_parallel = results_5_parallel.params['max_iterations']
# Get the SNR from the simulation parameters
SNR_parallel = np.array(results_5_parallel.params['SNR'])
# Can only plot if we simulated for more then one value of SNR
if SNR_parallel.size > 1:
fig = figure(figsize=(12,9))
semilogy(SNR_parallel, ber_parallel, '--g*', label='BER')
semilogy(SNR_parallel, ser_parallel, '--b*', label='SER')
xlabel('SNR')
ylabel('Error')
title('Min Leakage IA Algorithm ({5} Iterations)\nK={0}, Nr={1}, Nt={2}, Ns={3}, {4}'.format(K, Nr, Nt, Ns, modulator_name, ia_iterations_parallel))
legend()
grid(True, which='both', axis='both')
show()